
from Interface import System

class MemberSystem(System):
    #成员变量----------------------------------

    #信息
    lt = []
    # 敏感字
    no_user =[]
    # 字母
    letters = []

    #成员方法--------------------------------

    #构造
    def __int__(self):
        # 信息
        self.lt = []
        # 敏感字
        self.no_user = ['笨', '蠢', '死']
        # 字母
        self.letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
                   'u',
                   'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
                   'P',
                   'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    #添加
    def Add(self):
        # 临时储存信息
        info = dict()
        print("******* 欢迎进入会员添加界面 *******")

        # 性别
        new_id = input("请输入需要添加会员的性别（男 or 女）：")
        info["id"] = new_id

        # 姓名
        while True:
            new_user = input("请输入需要添加会员的姓名：")

            # 检查姓名是否已存在
            flag_exists = False
            for it in self.lt:
                for value in it.values():
                    if value == new_user:
                        print("名字已存在，请重新输入")
                        flag_exists = True
                        break
                if flag_exists:
                    break
            if flag_exists:
                continue

                # 检查敏感字符并替换
            new_user_list = list(new_user)
            flag_sensitive = False
            sensitive_chars = []
            for i in range(len(new_user_list)):
                if new_user_list[i] in self.no_user:
                    sensitive_chars.append(new_user_list[i])
                    new_user_list[i] = '*'
                    flag_sensitive = True

            new_user = ''.join(new_user_list)

            # 如果找到敏感字符，则打印错误信息并重新输入
            if flag_sensitive:
                print(f"{new_user}|姓名包含敏感词{''.join(sensitive_chars)},不可注册,重新输入")
                continue
            else:
                # 如果没有找到敏感字符，则跳出循环
                break

        info["name"] = new_user

        # 手机号码
        while True:
            new_phone = input("请输入需要添加的手机号码：")
            info["phone"] = new_phone

            if any(user_1 in new_phone for user_1 in self.letters):
                print("手机号不能含有字母，请重新输入")
                continue

            if len(new_phone) != 11:
                print("手机号数目有误，请重新输入")
                continue
            break

        # 储存
        self.lt.append(info)
        print("您好！")
        print(f'您添加的性别为:{new_id}')
        print(f"您注册的姓名为 :{new_user}")
        print(f"您注册的手机号为 :{new_phone}")
        print("******* 已经添加成功！*******")
        print("")

    #删除
    def Delete(self):
        Find_name = input("请输入需要删除会员的姓名：")
        flag = 0
        Find = 0
        for it in self.lt:
            for key, value in it.items():
                if value == Find_name:
                    Find = flag
            flag += 1

        if Find != 0:
            self.lt.pop(Find)
            print("删除成功！")
            print("")
            self.Show()
            return 0
        else:
            print("未存在该会员")
            print("")

    #修改
    def Modify(self):
        in_put = input("请输入需要修改信息的姓名：")
        flag = 0
        Find = 0
        for it in self.lt:
            for key, value in it.items():
                if value == in_put:
                    Find = flag
            flag += 1
        if flag == len(self.lt) - 1 and Find == 0:
            print("用户不存在")
            return 0

        # 查找下标
        flag = 0
        Find = 0
        for it in self.lt:
            for key, value in it.items():
                if value == in_put:
                    Find = flag
            flag += 1
        # 删除需要修改的
        self.lt.pop(Find)
        ######################################
        # 新建修改后的

        # 临时储存信息
        info = dict()
        # 编号
        new_id = input("请输入修改后的编号：")
        info["id"] = new_id

        # 姓名
        while True:
            new_user = input("请输入修改后的姓名：")
            new_user_list = list(new_user)
            if any(user_1 in new_user for user_1 in self.no_user):
                k = 0
                old_ = []
                for i in new_user:
                    for j in self.no_user:
                        # 找敏感字符
                        if i == j:
                            old_.append(new_user[k])
                            new_user_list[k] = '*'
                            new_user = ''.join(new_user_list)
                            break
                    k += 1
                print(f"{new_user}|姓名包含敏感词{old_},不可注册,重新输入")
                continue
            break

        info["name"] = new_user

        # 手机号码
        while True:
            new_phone = input("请输入修改后的手机号码：")
            info["phone"] = new_phone

            if any(user_1 in new_phone for user_1 in self.letters):
                print("手机号不能含有字母，请重新输入")
                continue

            if len(new_phone) != 11:
                print("手机号数目有误，请重新输入")
                continue
            break

        # 储存
        self.lt.insert(Find, info)
        print("您好！")
        print(f'修改后的编号为:{new_id}')
        print(f"修改后的姓名为 :{new_user}")
        print(f"修改后的手机号为 :{new_phone}")
        print("******* 已经修改成功！*******")
        print("")

    #查找
    def Find(self):
        in_put = input("请输入需要查询信息的姓名：")
        flag = 0
        Find = 9999
        for it in self.lt:
            for key, value in it.items():
                if value == in_put:
                    Find = flag
            flag += 1
        if Find == 9999:
            print("用户不存在")
            return 0
        print("会员信息：")
        flag_2 = 0
        for it in self.lt:
            flag_3 = 1
            for key, value in it.items():
                if flag_2 == Find:
                    if flag_3 == 1:
                        print(f"会员性别：{value}")
                        flag_3 += 1
                    elif flag_3 == 2:
                        print(f"会员姓名：{value}")
                        flag_3 += 1
                    elif flag_3 == 3:
                        print(f"会员手机号：{value}")
                        break
            flag_2 += 1
        print("")

    #遍历
    def Show(self):
        print("会员信息：")
        for it in self.lt:
            print("-----------------------")
            flag = 1
            for key, value in it.items():
                if flag == 1:
                    print(f"会员性别：{value}")
                    flag += 1
                elif flag == 2:
                    print(f"会员姓名：{value}")
                    flag += 1
                elif flag == 3:
                    print(f"会员手机号：{value}")
                    break
            print("-----------------------")











